/*******************************************************************************
 Configuration Information:
 Repository: Integrity Source
 Name      : $RCSfile: AR_PVS_CtrlrPrm.c $
 Version   : $Revision: 1.4 $
 Author    : $Author: Jack Jin (JinC5) $
 Date      : $Date: 2018/09/14 18:33:15IST $
 Location  : $ProjectName: /Steering/Projects/Geely/CMA_DP/PR48756_LVS_ENG_APP_Geely_CMA_EPS_DP_SYS_HRoom_AP/30_Software/3040_Design/S2-Application/01-Development/V00-Mainline/04-Components/ActiveReturn_Ear/Source/project.pj $
********************************************************************************

   ZF Friedrichshafen AG owns the copyright in this document and associated
   documents and all rights are reserved.  These documents must
   not be used for any purpose other than that for which they
   are supplied and must not be copied in whole or in part or
   disclosed to others without prior written consent of ZF Friedrichshafen AG.
   Any copy of this drawing or document made by any method
   must also include a copy of this legend.

   (C) ZF Friedrichshafen AG 2018

*******************************************************************************/
/**************************************************************************************************\
 *** 
 *** Simulink model       : AR_PVS_CtrlrPrm_tl
 *** TargetLink subsystem : AR_PVS_CtrlrPrm_tl
 *** Codefile             : AR_PVS_CtrlrPrm.c
 ***
 *** Generated by TargetLink, the dSPACE production quality code generator
 *** Model version: 1.89
 *** Generation date: 2018-09-14 10:59:19
 ***
 *** CODE GENERATOR OPTIONS:
 *** Code generation mode                     : AUTOSAR
 *** AUTOSAR version                          : 4.2.2
 *** Compiler                                 : <unknown>
 *** Target                                   : Generic
 *** ANSI-C compatible code                   : yes
 *** Code Optimization                        : enabled
 *** Constant style                           : decimal
 *** Clean code option                        : enabled
 *** Logging mode                             : Do not log anything
 *** Code Coverage                            : disabled
 *** Generate empty conditional branches      : disabled
 *** Loop unroll threshold                    : 5
 *** Shift mode                               : automatic
 *** Handle unscaled SF expr. with TL type    : enabled
 *** Assignment of conditions                 : AllBooleanOutputs 
 *** Scope reduction only to function level   : disabled
 *** Exploit ranges if not erasable           : disabled
 *** Exploit Compute Through Overflow         : never
 *** Linker sections                          : enabled
 *** Enable Assembler                         : disabled
 *** Variable name length                     : unlimited
 *** Use global bitfields                     : disabled
 *** Stateflow: use of bitfields              : enabled
 *** State activity encoding limit            : 8
 *** Omit zero inits in restart function      : disabled
 *** Share functions between TL subsystems    : disabled
 *** Generate 64bit functions                 : disabled
 *** Inlining Threshold                       : 6
 *** Line break limit                         : 100
 *** Target optimized boolean data type       : enabled
 *** Keep saturation elements                 : disabled
 *** Extended variable sharing                : disabled
 *** Extended lifetime optimization           : enabled
 *** Style definition file                    : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\Con
 ***                                            fig\codegen\cconfig.xml
 *** Root style sheet                         : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\XML
 ***                                            \CodeGen\Stylesheets\TL_CSourceCodeSS.xsl
 ***
 *** SUBSYS                   CORRESPONDING SIMULINK SUBSYSTEM
 *** SAR_PVS_011              AR_PVS_CtrlrPrm_tl
 *** SAR_PVS_012              AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm
 *** SAR_PVS_013              AR_PVS_CtrlrPrm_tl/DocFunction
 *** SAR_PVS_014              AR_PVS_CtrlrPrm_tl/IncludeAppHeader
 *** SAR_PVS_015              AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs
 *** SAR_PVS_016              AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2
 *** SAR_PVS_017              AR_PVS_CtrlrPrm_tl/DocFunction/EmptySubsystem
 *** 
 *** SUBSYS                   CORRESPONDING MODEL BLOCK (REFERENCED MODEL)
 *** 
 *** SF-NODE   CORRESPONDING STATEFLOW NODE                           DESCRIPTION
 *** 
 *** TargetLink version      : 4.2p2 from 27-Nov-2017
 *** Code generator version  : Build Id 4.2.0.33 from 2017-11-28 14:39:24

\**************************************************************************************************/

#ifndef AR_PVS_CTRLRPRM_C
#define AR_PVS_CTRLRPRM_C

/*----------------------------------------------------------------------------*\
  DEFINES (OPT)
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INCLUDES
\*----------------------------------------------------------------------------*/

#include "Rte_ActiveReturnSwc.h"
#include "AR_PVS_CtrlrPrm_tl_lut.h"
#include "AR_PVS_CtrlrPrm.h"

/*----------------------------------------------------------------------------*\
  ENUMS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  DEFINES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  TYPEDEFS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  VARIABLES
\*----------------------------------------------------------------------------*/

/******************************************************************************\
   VC_STRUCT_InitAtDef: Used for global struct variables. Initialised at definition. Creates access 
   functions (get and set). | Width: N.A.
\******************************************************************************/
struct tAR_PVS_CtrlrPrm_tag var_AR_PVS_CtrlrPrm = {
   0, /* EarSpdIndex */
   0.F, /* EarLim */
   0.F /* EarSpdFraction */
};

/* Custom code: AR_PVS_CtrlrPrm_tl/IncludeAppHeader/CC_AppHeaderInclude << declaration code >> */
#include "Rte_ActiveReturnSwc.h"
/*----------------------------------------------------------------------------*\
  PARAMETERIZED MACROS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION PROTOTYPES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INLINE FUNCTIONS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/

/**************************************************************************************************\
 ***  FUNCTION:
 ***      AR_PVS_CtrlrPrm
 *** 
 ***  DESCRIPTION:
 ***      
 *** 
 ***  PARAMETERS:
 ***      Type               Name                Description
 ***      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ***      Kph                FildVehSpd          
 ***
 ***  RETURNS:
 ***      void
 ***
 ***  SETTINGS:
 ***
\**************************************************************************************************/
void AR_PVS_CtrlrPrm(Kph FildVehSpd)
{
   /* SLLocal: Default storage class for local variables | Width: 32 */
   float32 SAR_PVS_015_Switch;
   float32 SAR_PVS_016_Switch;

   /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Switch
      AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Switch: Omitted comparison with constant.
      # combined # Relational: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Relational Operator
    */
   if (FildVehSpd < 0.F) {
      /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Switch
         # combined # Gain: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Gain */
      SAR_PVS_016_Switch = FildVehSpd * -1.F;
   }
   else {
      /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs2/Switch */
      SAR_PVS_016_Switch = FildVehSpd;
   }

   /* TableLookup: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/EAR_LIMIT_MAP */
   var_AR_PVS_CtrlrPrm.EarLim = Tab1DnMS0I2T3126_AR_PVS_01(5, (const float32 *)
    &(Rte_CData_EAR_LIM_VEH_SPD_BRKPTS()[0]), (const float32 *) &(Rte_CData_EAR_LIMIT_MAP()[0]),
    SAR_PVS_016_Switch);

   /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Switch
      AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Switch: Omitted comparison with constant.
      # combined # Relational: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Relational Operator */
   if (FildVehSpd < 0.F) {
      /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Switch
         # combined # Gain: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Gain */
      SAR_PVS_015_Switch = FildVehSpd * -1.F;
   }
   else {
      /* Switch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/ZFDivA_fabs/Switch */
      SAR_PVS_015_Switch = FildVehSpd;
   }

   /* IndexSearch: AR_PVS_CtrlrPrm_tl/AR_PVS_CtrlrPrm/Prelookup
      # combined # TargetLink outport: AR_PVS_CtrlrPrm_tl/EarSpdIndex
      # combined # TargetLink outport: AR_PVS_CtrlrPrm_tl/EarSpdFraction */
   TabIdxS48T3078_AR_PVS_01((const float32 *) Rte_Prm_TUNDAT_VEHICLE_SPEED_BREAKPOINTS(), 12,
    SAR_PVS_015_Switch, &(var_AR_PVS_CtrlrPrm.EarSpdIndex), &(var_AR_PVS_CtrlrPrm.EarSpdFraction));
}

/**************************************************************************************************\
 ***  FUNCTION:
 ***      Tab1DnMS0I2T3126_AR_PVS_01
 *** 
 ***  DESCRIPTION:
 ***      Generated function for look-up tables.
 *** 
 ***  PARAMETERS:
 ***      Type               Name                Description
 ***      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ***      uint8              Nx                  number of axis points
 ***      const float32 *    x_table             vector with x-values
 ***      const float32 *    z_table             vector with z-values
 ***      float32            x                   table input
 ***
 ***  RETURNS:
 ***      float32
 ***
 ***  SETTINGS:
 ***      Search algorithm...................: linear search, start low
 ***      Look-up method.....................: Interpolation - Use end values
 ***      Distances fit into given bitlengths: no
 ***      Behavior at boundaries.............: no
 ***      Starting point.....................: - (non-equidistant implementation)
 ***      Scaling unit.......................: - (non-equidistant implementation)
 ***
\**************************************************************************************************/
float32 Tab1DnMS0I2T3126_AR_PVS_01(uint8 Nx, const float32 * x_table, const float32 * z_table,
  float32 x)
{
   if (x <= *x_table) {
      /* Saturation. */
      return z_table[0];
   }
   if (x >= x_table[(uint8) (Nx - ((uint8) 1))]) {
      return z_table[(uint8) (Nx - ((uint8) 1))];
   }

   /* Linear search, start low. */
   x_table++;
   while (x > *(x_table++)) {
      z_table++;
   }
   x_table -= 2;

   /* Interpolation. */
   return (z_table[0] + (((z_table[1] - z_table[0]) * (x - x_table[0])) / (x_table[1] -
    x_table[0])));
}

/*----------------------------------------------------------------------------*\
  MODULE LOCAL FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/
#endif /* AR_PVS_CTRLRPRM_C */
/*----------------------------------------------------------------------------*\
  END OF FILE
\*----------------------------------------------------------------------------*/
